{% extends 'base_main.html' %}
{% block title %}
    学生列表
{% endblock %}

{% block extCSS %}
    <link href="/static/css/haiersoft.css" rel="stylesheet" type="text/css" media="screen,print"/>
{#    <link href="/static/css/print.css" rel="stylesheet" type="text/css" media="print"/>#}
{% endblock %}

{% block extJS %}
    <script src="/static/js/jquery-1.10.1.min.js"></script>
    <script src="/static/js/side.js" type="text/javascript"></script>
    <script>
        function delstu(i) {
            alert(i)
            csrf = $('input[name="csrfmiddlewaretoken"]').val();
            $.ajax({
                url:'/app/api/student/' + i + '/',
                type: 'DELETE',
                dataType:'json',
                headers:{'X-CSRFToken':csrf},
                success: function (msg) {
                    location.href ='/app/student/'
                },
                error:function(msg){
                    alert('删除失败')
                },
            });
        }

        $(document).ready(function () {
            $.get('/app/api/student/',function () {

            },'json');

        });

    </script>
{% endblock %}

{% block indexbody %}
    <!-- MainForm -->
<div id="MainForm">
    <div class="form_boxA">
        <h2>学生信息列表</h2>
        {% csrf_token %}
        <table cellpadding="0" cellspacing="0">
            <tr>
                <th>序号</th>
                <th>学生名称</th>
                <th>班级</th>
                <th>头像</th>
                <th>操作</th>
            </tr>
            {% for page in pages %}
            <tr>
                <td>{{ page.id }}</td>
                <td>{{ page.s_name }}</td>
                <td>{{ page.g.g_name }}</td>
                <td><img src="/media/{{ page.s_img }}" width='50' height="50"></td>
{#                <td><a href="{% url 'app:delete' %}?id={{ page.id }}">删除</a></td>#}
                <td><a href="javascript:;"onclick="delstu({{ page.id }})">删除</a></td>
            </tr>
            {% endfor %}
        </table>
        <p class="msg">共找到{{ total }}学生记录</p>
    </div>

    <ul id="PageNum">

        <li><a href="{% url 'app:student' %}">首页</a></li>
        {% if pages.has_previous %}
        <li><a href="{% url 'app:student' %}?page_num={{ pages.previous_page_number }}">上一页</a></li>
        {% endif %}
        {% for i in pages.paginator.page_range %}
        <li><a href="{% url 'app:student' %}?page_num={{ i }}">{{ i }}</a></li>
        {% endfor %}
        {% if pages.has_next %}
        <li><a href="{% url 'app:student' %}?page_num={{ pages.next_page_number }}">下一页</a></li>
        {% endif %}
        <li><a href="{% url 'app:student' %}?page_num={{ pages.paginator.num_pages }}">尾页</a></li>
        <li>当前第{{ pages.number }}页</li>
    </ul>

</div>
{% endblock %}
